﻿Imports System.Xml

Namespace HybrisItems.Model

    ''' <summary>
    ''' A RelationType defines a n-m or 1-n relation between types.
    ''' </summary>
    ''' <remarks></remarks>
    <Serializable()> _
    Public Class RelationModel

        Public Sub New()

        End Sub

        Public Sub New(Node As XmlNode)

            Fill(Node)

        End Sub

        ''' <summary>
        ''' Is this Model object correctly wired to its related Model objects
        ''' </summary>
        ''' <remarks></remarks>
        Public ReadOnly Property IsWired As Boolean
            Get
                Return Me.SourceElement.IsWired AndAlso Me.TargetElement.IsWired
            End Get
        End Property

        Public Sub Fill(Node As XmlNode)

            Me.Description = ConfigParser.GetAttribute(Node, "description")

            'ToDo: Unset Config Properties
            ' Me.Deployment

            Me.SourceElement = New RelationElementModel(Node.Item("sourceElement"))
            Me.TargetElement = New RelationElementModel(Node.Item("targetElement"))
            Me.Code = New CodeModel(Node)

            'ToDo: Unset Config Properties
            ' Me.Localized
            ' Me.AutoCreate

        End Sub

        Public Sub Wire(Model As EntireHybrisSystemModel)

            Me.SourceElement.Wire(Model)
            Me.TargetElement.Wire(Model)

        End Sub

#Region "Config Properties"

        ''' <summary>
        ''' Provides possibility to add meaningfull description phrase 
        ''' for a generated model class.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Description As String

        ''' <summary>
        ''' Configures deployment information 
        ''' for this relation (table name and typecode).
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Deployment As DeploymentModel

        ''' <summary>
        ''' Configures the generated attribute at source relation end
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property SourceElement As RelationElementModel

        ''' <summary>
        ''' Configures the generated attribute at target relation end
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property TargetElement As RelationElementModel

        ''' <summary>
        ''' The typecode.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Code As CodeModel

        ''' <summary>
        ''' A localized n-m relation can have 
        ''' a link between two items for each language.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Localized As Boolean

        ''' <summary>
        ''' If 'true', the item will be created during initialization.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property AutoCreate As Boolean

#End Region

    End Class

End Namespace
